use std::{
   sync::mpsc::{self}, thread
};
fn main() {
    // 通道有两个端点:'Sender<T>'和'Receiver<T>',其中'T'是要发送
    // 的消息的类型(类型标注是可选的)
    let (tx, rx) = mpsc::channel();
    let tx1 = mpsc::Sender::clone(&tx);
    let tx2 = mpsc::Sender::clone(&tx);

    let handle1 = thread::spawn(move || {
        let values = vec![
            String::from("hi"),
            String::from("from"),
            String::from("the"),
            String::from("thread"),
        ];
        for val in values{
            tx1.send(val).unwrap();
        }
    });
    let handle2 = thread::spawn(move || {
        let values = vec![
            String::from("a"),
            String::from("b"),
            String::from("c"),
            String::from("d"),
        ];
        for val in values{
            tx.send(val).unwrap();
        }
    });
    let handle3 = thread::spawn(move || {
        let values = vec![
            String::from("A"),
            String::from("B"),
            String::from("C"),
            String::from("D"),
        ];
        for val in values{
            tx2.send(val).unwrap();
        }
    });
    handle1.join().unwrap();
    handle2.join().unwrap();
    handle3.join().unwrap();
    for rec in rx {
        println!("Got: {}", rec);
    }
}
